package cn.codergege.demo.controller;

import cn.codergege.demo.Service.EmployeeService;
import cn.codergege.demo.domain.Employee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/employee")
public class EmployeeController {
    private final Logger log = LoggerFactory.getLogger(EmployeeController.class);

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/employees")
    public Object getAllEmployees() {
        List<Employee> employees = employeeService.getAllEmployees();
        log.info("--------------------> employee 数量: {}", employees.size());
        return employees;
    }

    @RequestMapping(value = "/employee", method = RequestMethod.POST)
    public void save(@RequestBody Employee employee) {
        log.info("--------------------> 开始保存 employee...");
        employeeService.save(employee);
        log.info("--------------------> 保存 employee 完成");
    }
}
